﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using iOak.Data.Resumes;
using iOak.Domain.Resumes;
using AutoMapper;

namespace iOak.Business.Resumes
{
    public partial class ResumeTemplateFieldsService
    {
        private static readonly ResumeTemplateFieldsRepository resumeTemplateFields = new ResumeTemplateFieldsRepository("master");
        private ResumeFieldService itemResumeFieldService = new ResumeFieldService();
        public List<ResumeTemplateField> GetListByTemplateId(Guid resumeTemplateId, bool blReport = false)
        {
            return resumeTemplateFields.GetListByTemplateId(resumeTemplateId, blReport);
        }

        public List<ResumeField> ChangeListToField(List<ResumeTemplateField> currentList, bool blReport = false)
        {
            var returnList = new List<ResumeField>();
            currentList.ForEach(m =>
                {

                    var item = itemResumeFieldService.Retrieve(m.ResumeFieldId);

                    if (item != null)
                    {
                        item.Reqiured = m.Reqiured;
                        if (m.ListNumber != null)
                        {
                            item.ListNumber = (int)m.ListNumber;
                        }
                        if (m.Width != null)
                        {
                            item.Width = (int)m.Width;
                        }

                        // 报告显示
                        item.ReportNumber = m.ReportNumber;
                        item.ReportValue = m.ReportValue;
                        item.LoadMethod = m.LoadMethod;
                        item.LoadParameter = m.LoadParameter;
                        item.ColDisplay = m.ColDisplay;
                        item.ReportWidth = m.ReportWidth;
                        item.CandidateField = m.CandidateField;
                        item.IsSumField = m.IsSumField;
                        item.SumFormat = m.SumFormat;
                        item.DisplayName = m.DisplayName;
                        if (blReport)
                        {
                            item.LabelText = m.ReportLabel;
                        }
                        returnList.Add(item);
                    }
                });

            return returnList;
        }

        public List<ResumeField> GetReportField(Guid resumeTemplateId)
        {
            var listResumeTemplateField = this.GetListByTemplateId(resumeTemplateId, false);
            return this.ChangeListToField(listResumeTemplateField, false);
        }
    }
}
